package com.openway.game.personage;

/**
 * Abstract implementation of {@link GameObject} interface.
 * Game objects should extends this class.
 *
 * @author Created: 04.03.12 12:19
 * @version $Date$ $Revision$
 */
public abstract class AbstractGameObject implements GameObject {
    private static int nextId = 1;

    private int id;

    protected AbstractGameObject() {
        this.id = nextId;
        nextId++;
    }

    public int getId() {
        return id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        AbstractGameObject that = (AbstractGameObject) o;

        return id == that.id;
    }

    @Override
    public int hashCode() {
        return id;
    }
}
